package com.feng.listener;

import com.alibaba.fastjson.JSONObject;
import com.feng.config.EmailConfig;
import com.feng.service.UserService;
import com.feng.util.StringUtil;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;


/**
 * 消费消息
 * @author: 丰
 * @date: 2023/1/11 16:54
 */
@Component
public class RabbitMqListener {
    @Autowired
    private EmailConfig emailConfig;


    @RabbitListener(queues = {"feng.send"})
    public void receive(String message){
        JSONObject jsonObject = JSONObject.parseObject(message);
        Map<String, String> hashMap = jsonObject.toJavaObject(Map.class);
        String username = hashMap.get("username");
        String email = hashMap.get("email");
        // sendTextMailMessage("1507298022@qq.com","测试内容","又是充满希望的一天");
        String emailMessage = "用户【" +  username + "】在【" + StringUtil.getStringDate() + "】登录后台系统成功";
        emailConfig.sendTextMailMessage(email, "登录信息", emailMessage);
    }
}
